
//#include "pts.hpp"
/* pt class begins here */
#define _Ty lod
class pt
{
public:
    _Ty x, y;
    pt (_Ty _x = 0, _Ty _y = 0)
    {
        x = _x, y = _y;
    }
};

bool operator == (pt a, pt b)
{	return abs(a.x - b.x) < eps && abs(a.y - b.y) < eps; }
pt operator + (pt a, pt b)
{   return pt(a.x + b.x, a.y + b.y); }
pt operator - (pt a, pt b)
{   return pt(a.x - b.x, a.y - b.y); }
pt operator - (pt a)
{   return pt() - a; }
_Ty operator * (pt a, pt b)
{   return a.x * b.x + a.y * b.y; }
_Ty operator & (pt a, pt b)
{   return a.x * b.y - a.y * b.x; }
pt operator * (pt a, _Ty q)
{   return pt(a.x * q, a.y * q); }
pt operator / (pt a, _Ty q)
{   return a * (1 / q); }
_Ty abs(pt a)
{   return sqrt(a * a);}
_Ty dist(pt a, pt b)
{   return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); }
pt rotate(pt a, _Ty angle)
{	return pt(a.x * cos (angle) - a.y * sin(angle), a.x * sin(angle) + a.y * cos(angle)); }

/* pt class ends   here */

bool intersect_segments(pair <pt, pt> first, pair <pt, pt> second, pt &result)
{
	pt dir1 = first.second - first.first;
	pt dir2 = second.second - second.first;

	// line equations
	double
		a1 = -dir1.y,
		b1 = +dir1.x,
		c1 = -(a1 * first.first.x + b1 * first.first.y);
	double
		a2 = -dir2.y,
		b2 = +dir2.x,
		c2 = -(a2 * second.first.x + b2 * second.first.y);

	// in which semiplains are those endings?
	double 
		seg1_start  = a2 * first.first.x   + b2 * first.first.y   + c2,
		seg1_finish = a2 * first.second.x  + b2 * first.second.y  + c2,
		seg2_start  = a1 * second.first.x  + b1 * second.first.y  + c1,
		seg2_finish = a1 * second.second.x + b1 * second.second.y + c1;

	if (seg1_start == 0 && seg1_finish == 0 && seg2_start == 0 && seg2_finish == 0)
		// points are on a single line
	{
		double
			temp1 = (second.first - first.first) * (first.second - first.first),
			temp2 = (second.second - first.first) * (first.second - first.first),
			temp3 = abs(second.first - first.first),
			temp4 = abs(first.second - first.first);
		
		if (
			!(
				(second.first - first.first) * (first.second - first.first) >= 0 
				&& abs(second.first - first.first) <= abs(first.second - first.first)
			)
			&& 
			!(
				(second.second - first.first) * (first.second - first.first) >= 0 
				&& abs(second.second - first.first) <= abs(first.second - first.first)
			)
			&& 
			!(
				(first.first - second.first) * (second.second - second.first) >= 0
				&& abs(first.first - second.first) <= abs(second.second - second.first)
			)
			&& 
			!(
				(first.second - second.first) * (second.second - second.first) >= 0
				&& abs(first.second - second.first) <= abs(second.second - second.first)
			)
			)
			// each of second segment's points are not between first segment's endings
			return false;
	}
	if (seg1_start * seg1_finish > 0 || seg2_start * seg2_finish > 0)
		// no intersection, because both points are in one semiplain 
		return false;

	double param = seg2_start / (seg2_finish - seg2_start);
	result = seg1_start + param * dir1;
	return true;
}

/*
int main()
{
#ifdef CUCUMBER
	freopen("input.txt",  "r",  stdin);
	freopen("output.txt", "w+", stdout);
	freopen("log.txt",    "w+", stderr);
#endif

	pt a, b, c, d, loc;
	cin >> a.x >> a.y
		>> b.x >> b.y
		>> c.x >> c.y
		>> d.x >> d.y;
	if (intersect_segments(mp(a, b), mp(c, d), loc))
		cout << "YES";
	else
		cout << "NO";

	return 0;
} 
*/
